﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aerthe.Model.Tasks
{
    public class MTask4
    {
        public List<ListsItem> ListTask = new List<ListsItem> { };
        string BuforString;

        public MTask4()
        {
            using (var Base = new NorthwindEntities())
            {
                var ListDepot = Base.Suppliers.Select(m => new
                {
                    supiler = m,
                    Lproduct = m.Products.Select(n => n.ProductName)
                });

                foreach (var a in ListDepot)
                {
                    foreach (var b in a.Lproduct)
                    {
                        this.ListTask.Add(new ListsItem(
                        a.supiler.ContactName.Trim(),
                        b.ToString().Trim()
                        ));
                    }
                }
            }
        }

        public void MViewConsole()
        {
            Console.WriteLine("|  {0,-35} |  {1} ", "Suppiler", "Products");

            foreach (var a in this.ListTask)
            {
                if (this.BuforString == a.Item1)
                {
                    Console.Write(", {0}", a.Item2);
                }
                else
                {
                    this.BuforString = a.Item1;

                    Console.Write("\n|  {0,-35} |  {1}", a.Item1, a.Item2);
                }
            }

            Console.WriteLine("");
        }
    }
}
